package com.jeespring.shardingjdbc.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jeespring.shardingjdbc.entity.User;
import com.jeespring.shardingjdbc.service.OrderService;
import com.jeespring.shardingjdbc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author 张朝阳
 * @description UserController
 * @date 2021/11/16 0:26:26
 */
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("/select")
    public List<User> select(@RequestBody User user) {
        return userService.select(user);
    }

    @RequestMapping("/selectPage")
    public IPage<User> selectPage(User user, int pageNumber, int pageSize) {
        return userService.selectPage(user, pageNumber, pageSize);
    }

    @RequestMapping("/selectAll")
    public List<User> selectAll() {
        return userService.selectAll();
    }

    @RequestMapping("/insert")
    public int insert(@RequestBody User user) {
        return userService.insert(user);
    }

    @RequestMapping("/update")
    public int update(@RequestBody User user) {
        if (user.getId() == null) {
            return 0;
        }
        return userService.update(user);
    }

    @RequestMapping("/delete")
    public int delete(@RequestBody User user) {
        if (user.getId() == null) {
            return 0;
        }
        return userService.delete(user);
    }
}
